"""
作者:张琪
页面:商品管理-添加新商品-通用信息
"""
import time
from Common.Base import Base, open_browser

information_url = 'http://172.16.11.206:8080/ecshop/admin/index.php'


class GoodsGeneralInformation(Base):
    """制作定位器"""
    cancel_submit_loc = ('css selector', 'div.panel-cross span')  # Ｘ按钮
    ecseshop_loc = ('id', 'cloudLogin')  # ECShop定位
    username_loc = ('name', 'username')  # 用户名输入框
    password_loc = ('name', 'password')  # 密码输入框
    login_submit_loc = ('class name', 'btn-a')  # 登录按钮
    goods_management_frame = ('id', 'menu-frame')  # 商品管理链接frame
    goods_management = ('class name', 'icon-goods')  # 商品管理链接
    add_goods = ('css selector', 'a[href*="goods.php?act=add"]')  # 添加新商品链接
    general_information_frame = ('id', 'main-frame')  # 通用信息frame
    EC_management_center = ('css selector', 'a[href*="index.php?act=main"]')  # ECShop管理中心
    goods_list = ('css selector', 'a[href*="goods.php?act=list"]')  # 商品列表链接
    goods_name = ('name', 'goods_name')  # 商品名称输入框
    font_format_first = ('css selector', 'select[name="goods_name_style"]>option:nth-of-type(2)')  # 选择字体格式
    font_format_last = ('css selector', 'select[name="goods_name_style"]>option:nth-of-type(5)')  # 选择字体格式为删除线
    goods_code_submit = ('css selector', 'a[href*="javascript:showNotice("]')  # 商品货号提示信息按钮
    goods_code_message = ('class name', 'notice-span')  # 商品货号提示信息
    goods_code = ('name', 'goods_sn')  # 商品货号输入框

    goods_categories_first = ('css selector', 'select[name="cat_id"]>option:nth-of-type(2)')  # 选择商品类别为家用电器
    goods_categories_last = ('css selector', 'select[name="cat_id"]>option:nth-of-type(22)')  # 选择商品类别为3G手机
    goods_categories_add = ('css selector', 'button[onclick*="rapidCatAdd()"]')  # 添加分类按钮
    goods_categories_input = ('css selector', 'input[name*="addedCategoryName"]')  # 添加分类名输入框
    goods_categories_add_define = ('css selector', 'button[onclick*="addCategory()"]')  # 添加分类确定按钮
    goods_categories_management = ('css selector', 'button[onclick="return goCatPage()"]')  # 分类管理按钮
    goods_categories_hidden = ('css selector', 'button[onclick="hideCatDiv()"]')  # 添加分类隐藏按钮
    shop_price = ('name', 'shop_price')  # 本店售价
    define_button = ('css selector', 'input[value*="确定"]')  # 确定按钮
    extended_add = ('css selector', 'input[value*="添加"]')  # 扩展分类添加按钮
    extended_goods_categories_first = (
        'css selector', 'select[name="other_cat[]"]>option:nth-of-type(2)')  # 选择商品类别为家用电器
    extended_goods_categories_last = (
        'css selector', 'select[name="other_cat[]"]>option:nth-of-type(22)')  # 选择商品类别为3G手机
    brand_id_first = ('css selector', 'select[name="brand_id"]>option:nth-of-type(2)')  # 选择商品品牌为飞利浦
    brand_id_last = ('css selector', 'select[name="brand_id"]>option:nth-of-type(4)')  # 选择商品品牌为仓品
    brand_add = ('css selector', 'button[onclick="rapidBrandAdd()"]')  # 添加品牌按钮
    brand_id_input = ('css selector', 'input[name*="addedBrandName"]')  # 添加品牌输入框
    brand_id_add_define = ('css selector', 'button[onclick*="addBrand()"]')  # 添加品牌确定按钮
    brand_id_management = ('css selector', 'button[onclick="return goBrandPage()"]')  # 品牌管理按钮
    brand_id_hidden = ('css selector', 'button[onclick="hideBrandDiv()"]')  # 添加品牌隐藏按钮
    supplier_first = ('css selector', 'select[name="suppliers_id"]>option:nth-of-type(2)')  # 选择供货商为北京供货商
    supplier_last = ('css selector', 'select[name="suppliers_id"]>option:nth-of-type(3)')  # 选择供货商为上海供货商
    market_price_cal = ('css selector', 'input[onclick="marketPriceSetted()"]')  # 按市场价计算按钮
    member_price_submit = ('css selector', 'a[href*="noticeUserPrice"]')  # 会员价格提示信息按钮
    member_price_message = ('id', 'noticeUserPrice')  # 会员价格提示信息
    register_user = ('id', 'rank_1')  # 注册用户输入框
    consignment_user = ('id', 'rank_3')  # 代销用户输入框
    vip = ('id', 'rank_2')  # vip输入框
    preferential_price = ('css selector', 'a[href*="volumePrice"]')  # 商品优惠价格提示信息按钮
    preferential_price_message = ('id', 'volumePrice')  # 商品优惠价格提示信息
    preferential_num = ('name', 'volume_number[]')  # 优惠数量输入框
    preferential_price_input = ('name', 'volume_price[]')  # 优惠价格输入框
    add_preferential = ('css selector', 'a[onclick="addVolumePrice(this)"]')  # + 号按钮
    market_price = ('name', 'market_price')  # 市场售价输入框
    take_integer = ('css selector', 'input[onclick="integral_market_price()"]')  # 取整数按钮
    virtual_sales = ('css selector', 'input[name*="virtual_sales"]')  # 虚拟销量输入框
    give_integral_message = ('css selector', 'a[href*="giveIntegral"]')  # 赠送消费积分数提示信息
    give_integral = ('css selector', 'input[name*="give_integral"]')  # 赠送消费积分数输入框
    rank_integral_message = ('css selector', 'a[href*="rankIntegral"]')  # 赠送等级积分数提示信息
    rank_integral = ('css selector', 'input[name*="rank_integral"]')  # 赠送等级积分数输入框
    integral_message = ('css selector', 'a[href*="noticPoints"]')  # 积分购买金额提示信息
    integral = ('css selector', 'input[name*="integral"]')  # 积分购买金额输入框
    promotion_price = ('id', 'is_promote')  # 促销价按钮
    promotion_price_box = ('id', 'promote_1')  # 促销价输入框
    goods_img = ('name', 'goods_img')  # 上传商品图片按钮
    goods_thumb = ('name', 'goods_thumb')  # 上传商品缩略图按钮
    auto_thumb = ('name', 'auto_thumb')  # 自动生成缩略图按钮
    reset = ('css selector', 'input[value*="重置"]')  # 重置按钮
    add_goods_name = ('css selector', 'td.first-cell>span')  # 新增商品
    goods_list_frame = ('css selector', 'a[href*="goods.php?act=list"]')  # 商品列表frame
    is_on_sale_submit = ('xpath', '/html/body/div[3]/form/input[1]')  # 上架按钮
    search_submit = ('xpath', '/html/body/div[3]/form/button')  # 搜索按钮

    """封装操作层"""

    def login(self, username, password):
        """登录账号"""
        self.click(self.cancel_submit_loc)
        time.sleep(1)
        self.click(self.ecseshop_loc)
        self.send_keys(self.username_loc, username)
        self.send_keys(self.password_loc, password)
        self.click(self.login_submit_loc)

    def get_into_goods(self):
        """进入商品"""
        self.into_frame(self.goods_management_frame)
        self.click(self.goods_management)
        self.out_frame()

    def get_into_add_goods(self):
        """进入添加商品"""
        self.into_frame(self.goods_management_frame)
        self.click(self.add_goods)
        self.out_frame()

    def get_into_management(self):
        """点击ECShop管理中心链接"""
        self.into_frame(self.general_information_frame)
        self.click(self.EC_management_center)
        self.out_frame()

    def goods_list_click(self):
        """点击商品列表链接"""
        self.into_frame(self.general_information_frame)
        self.click(self.goods_list)
        self.out_frame()

    def goods_name_input(self, name):
        """商品名称"""
        self.into_frame(self.general_information_frame)
        self.send_keys(self.goods_name, name)

    def font_format_select_first(self):
        """选择字体样式first"""
        self.click(self.font_format_first)

    def font_format_select_last(self):
        """选择字体样式last"""
        self.click(self.font_format_last)

    def goods_code_message_show(self):
        """点击商品货号提示信息按钮"""
        self.click(self.goods_code_submit)

    def goods_code_input(self, code):
        """输入商品货号"""
        self.send_keys(self.goods_code, code)

    def goods_categories_select_first(self):
        """选择商品类别first"""
        self.click(self.goods_categories_first)

    def goods_categories_select_last(self):
        """选择商品类别last"""
        self.click(self.goods_categories_last)

    def shop_price_input(self, num):
        """输入本店售价"""
        self.clear(self.shop_price)
        self.send_keys(self.shop_price, num)

    def extended_add_click(self):
        """点击扩展分类添加按钮"""
        self.click(self.extended_add)

    def extended_goods_categories_select_first(self):
        """选择扩展分类的商品类别first"""
        self.click(self.extended_goods_categories_first)

    def extended_goods_categories_select_last(self):
        """选择扩展分类的商品类别last"""
        self.click(self.extended_goods_categories_last)

    def brand_id_select_first(self):
        """选择商品品牌first"""
        self.click(self.brand_id_first)

    def brand_id_select_last(self):
        """选择商品品牌last"""
        self.click(self.brand_id_last)

    def brand_add_click(self):
        """添加品牌按钮"""
        self.click(self.brand_add)

    def goods_categories_add_click(self):
        """添加分类按钮"""
        self.click(self.goods_categories_add)

    def goods_categories_add_input(self, name):
        """添加分类输入框"""
        self.send_keys(self.goods_categories_input, name)

    def goods_categories_define(self):
        """添加分类确定按钮"""
        self.click(self.goods_categories_add_define)
        time.sleep(1)

    def brand_add_input(self, name):
        """添加品牌输入框"""
        self.send_keys(self.brand_id_input, name)

    def brand_id_define(self):
        """添加品牌确定按钮"""
        self.click(self.brand_id_add_define)
        time.sleep(1)

    def supplier_selector_first(self):
        """选择供货商first"""
        self.click(self.supplier_first)

    def supplier_selector_last(self):
        """选择供货商last"""
        self.click(self.supplier_last)

    def market_price_click(self):
        """按市场价计算按钮"""
        self.click(self.market_price)

    def memebr_price_submit_click(self):
        """点击会员价格提示信息按钮"""
        time.sleep(1)
        self.click(self.member_price_submit)

    def register_user_input(self, num):
        """注册用户输入框输入"""
        self.clear(self.register_user)
        self.send_keys(self.register_user, num)

    def consignment_user_input(self, num):
        """代销用户输入框输入"""
        self.clear(self.consignment_user)
        self.send_keys(self.consignment_user, num)

    def vip_input(self, num):
        """vip输入框输入"""
        self.clear(self.vip)
        self.send_keys(self.vip, num)

    def preferential_price_click(self):
        """商品优惠价格提示信息按钮"""
        time.sleep(1)
        self.click(self.preferential_price)

    def preferential_num_input(self, num):
        """优惠数量输入框"""
        self.clear(self.preferential_num)
        self.send_keys(self.preferential_num, num)

    def preferential_price_in(self, num):
        """优惠价格输入框"""
        self.clear(self.preferential_price_input)
        self.send_keys(self.preferential_price_input, num)

    def add_preferential_click(self):
        """+号按钮"""
        time.sleep(1)
        self.click(self.add_preferential)

    def market_price_input(self, num):
        """市场售价输入框"""
        self.clear(self.market_price)
        self.send_keys(self.market_price, num)

    def take_integer_click(self):
        """取整数按钮"""
        time.sleep(1)
        self.click(self.take_integer)

    def virtual_sales_input(self, num):
        """虚拟销量输入框"""
        self.clear(self.virtual_sales)
        self.send_keys(self.virtual_sales, num)

    def give_integral_message_click(self):
        """赠送消费积分数提示信息按钮"""
        time.sleep(1)
        self.click(self.give_integral_message)

    def give_integral_input(self, num):
        """赠送消费积分数输入框"""
        self.clear(self.give_integral)
        self.send_keys(self.give_integral, num)

    def rank_integral_message_click(self):
        """赠送等级积分数提示信息按钮"""
        time.sleep(1)
        self.click(self.rank_integral_message)

    def rank_integral_input(self, num):
        """赠送等级积分数输入框"""
        self.clear(self.rank_integral)
        self.send_keys(self.rank_integral, num)

    def integral_message_click(self):
        """积分购买金额提示信息按钮"""
        time.sleep(1)
        self.click(self.integral_message)

    def integral_input(self, num):
        """积分购买金额输入框"""
        self.clear(self.integral)
        self.send_keys(self.integral, num)

    def promotion_price_click(self):
        """促销价按钮"""
        time.sleep(1)
        self.click(self.promotion_price)

    def promotion_price_input(self, num):
        """促销价输入框"""
        time.sleep(1)
        self.send_keys(self.promotion_price_box, num)

    def goods_img_click(self, addr):
        """上传商品图片按钮"""
        self.send_keys(self.goods_img, addr)

    def goods_thumb_click(self, addr):
        """上传商品缩略图按钮"""
        self.send_keys(self.goods_thumb, addr)

    def auto_thumb_click(self):
        """自动生成缩略图按钮"""
        self.click(self.auto_thumb)

    def reset_click(self):
        """重置按钮"""
        self.click(self.reset)

    def define(self):
        """点击确定按钮"""
        self.click(self.define_button)
        time.sleep(8)

    def is_add_success(self, text):
        """
        判断新增商品是否成功,如果成功,返回TRUE,反之返回False
        @return:
        """
        self.click(self.is_on_sale_submit)
        self.click(self.search_submit)
        return self.is_text_equal_in_element(self.add_goods_name, text)

    def font_format_first_is_selected(self, text):
        """
        判断字体样式选框first是否被选中
        @return:
        """
        return self.is_text_equal_in_element(self.font_format_first, text)

    def font_format_last_is_selected(self, text):
        """
        判断字体样式选框last是否被选中
        @return:
        """
        return self.is_text_equal_in_element(self.font_format_last, text)

    def message_submit_click(self):
        """判断货号提示信息是否存在"""
        time.sleep(1)
        return self.message_submit(self.goods_code_submit)

    def memebr_price_submit(self):
        """判断会员价格提示信息是否存在"""
        time.sleep(1)
        return self.message_submit(self.member_price_submit)

    def preferential_price_submit(self):
        """判断优惠价格提示信息是否存在"""
        time.sleep(1)
        return self.message_submit(self.preferential_price_message)

    def img_auto_thumb(self):
        """判断自动缩略图按钮是否被选中"""
        return self.is_selected_submit_radio(self.auto_thumb)

    def give_integral_message_submit(self):
        """判断赠送消费积分数提示信息是否存在"""
        return self.message_submit(self.give_integral_message)

    def give_integral_submit(self):
        """判断赠送等级积分数提示信息是否存在"""
        return self.message_submit(self.give_integral)

    def rank_integral_message_submit(self):
        """判断积分购买金额提示信息是否存在"""
        return self.message_submit(self.rank_integral_message)


if __name__ == '__main__':
    login = GoodsGeneralInformation(open_browser())  # 打开浏览器
    login.open_url(information_url)  # 进入商品详情页面
    login.login('root', 'root123456')  # 输入用户名,密码
    login.get_into_goods()  # 进入商品管理
    login.get_into_add_goods()  # 进入添加商品
    # login.get_into_management()#点击ECShop管理中心链接
    # login.goods_list_click()#点击商品列表链接
    login.goods_name_input('9999')  # 输入商品名称
    login.font_format_select_first()  # 选择字体样式
    login.font_format_select_last()  # 选择字体样式
    login.goods_code_message_show()  # 点击商品货号提示信息按钮
    # login.goods_code_input('1')#输入商品货号

    # login.goods_categories_select()#选择商品类别
    # login.goods_categories_add_click()#点击添加分类按钮
    # login.goods_categories_add_input("小小家电1")#输入分类名称
    # login.goods_categories_define()#点击添加分类确定按钮

    login.shop_price_input("10000")  # 输入本店售价
    login.extended_add_click()  # 点击扩展分类添加按钮
    login.extended_goods_categories_select_first()  # 选择商品分类

    # login.brand_id_select()#选择商品品牌
    # login.brand_add_click()#点击添加商品品牌按钮
    # login.brand_add_input("飞利浦22397")#输入商品品牌名称
    # login.brand_id_define()#点击添加商品品牌确定按钮

    login.supplier_selector_first()  # 选择供货商
    login.market_price_click()  # 点击按市场价计算按钮
    login.memebr_price_submit_click()  # 点击会员价格提示信息按钮
    login.register_user_input("1")  # 注册用户框输入
    login.consignment_user_input("11")  # 代销用户框输入
    login.vip_input("111")  # vip框输入
    login.preferential_price_click()  # 点击商品优惠价格提示信息按钮
    login.preferential_num_input("100000")  # 输入优惠数量
    login.preferential_price_in("99")  # 输入优惠价格
    login.add_preferential_click()  # 点击+号按钮
    login.market_price_input("9999.9999")  # 输入市场售价
    login.take_integer_click()  # 点击取整数按钮
    login.virtual_sales_input("1123456")  # 虚拟销量输入框
    login.give_integral_message_click()  # 点击赠送消费积分数提示信息按钮
    login.give_integral_input("99")  # 输入赠送消费积分数
    login.rank_integral_message_click()  # 点击赠送等级积分数提示信息按钮
    login.rank_integral_input("99")  # 输入赠送等级积分数输入框
    login.integral_message_click()  # 点击积分购买金额提示信息按钮
    login.integral_input("99")  # 输入积分购买金额输入框
    login.promotion_price_click()  # 点击促销价按钮
    login.promotion_price_input("1999")  # 输入促销价输入框
    login.goods_img_click(r"D:\ceshi\Python\html和css\代码回敲\h2.jpg")  # 上传商品图片
    login.auto_thumb_click()  # 自动生成缩略图
    login.goods_thumb_click(r'D:\ceshi\Python\html和css\代码回敲\h2.jpg')  # 上传商品缩略图
    login.reset_click()  # 点击重置按钮

    # login.define()#点击确定按钮
